local status_ok, cmp = pcall(require, "cmp")
if not status_ok then
  vim.notify("Not found cmp")
end

cmp.setup({
  -- 指定 snippet 引擎
  snippet = {
    expand = function(args)
      -- For 'vsnip' users
      vim.fn["vsnip#anonymous"](args.body)

      -- For `luasnip` users.
      -- require('luasnip').lsp_expand(args.body)

      -- For `ultisnips` users.
      -- vim.fn["UltiSnips#Anon"](args.body)

      -- For `snippy` users.
      -- require'snippy'.expand_snippet(args.body)
    end,
  },
  -- 补全源配置
  sources = cmp.config.sources({
    -- Neovim内置LSP提供补全内容源
    { name = 'nvim_lsp' },
    -- For vsnip users
    { name = 'vsnip' },

    -- For luasnip users.
    -- { name = 'luasnip' },

    -- For ultisnips users.
    -- { name = 'ultisnips' },

    -- For snippy users.
    -- { name = 'snippy' },
    
    { name = 'buffer' },
    { name = 'path' },
  }),
  -- 快捷键设置
  mapping = require("keybindings").cmp(cmp),
  formatting = require("lsp.ui").formatting
})

-- / 查找模式使用 buffer 源
cmp.setup.cmdline("/", {
  mapping = cmp.mapping.preset.cmdline(),
  source = {
    { name = 'buffer' },
  },
})

-- : 命令行模式中使用 path 和 cmdline 源
cmp.setup.cmdline(":", {
  mapping = cmp.mapping.preset.cmdline(),
  sources = cmp.config.sources({
    { name = "path" },
    { name = "cmdline" },
  }),
})
